<?php

namespace App\Http\Controllers\Admin;

use App\Models\Deposit;
use App\Models\Store;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RedepositController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {
        view()->share([
            '_orders' => 'am-in',
            '_redeposit' => 'am-active',

        ]);

    }

//充值记录管理首页

    public function index(Request $request)
    {
        $where = function ($query) use ($request) {
            //根据个人或公司
            if ($request->has('statu') and $request->statu != '-1') {
                $query->where('statu', $request->statu);
            }

           //根据公司名或会员名
            if ($request->has('name') and $request->name != '') {
                $search = "%" . $request->name . "%";
                $query->where('oncustomer_name', 'like', $search)->orWhere('company_name','like',$search);
            }
            //根据会员电话或公司联系人电话
            if ($request->has('tel') and $request->tel != '') {
                $search = "%" . $request->tel . "%";
                $query->where('oncustomer_tel', 'like', $search)->orWhere('company_tel','like',$search);
            }
           //根据门店
            if($request->has('store_id')and $request->store_id !='-1'){

                $query->where('store_id',$request->store_id);
            }


        };
        //所有门店
        $cates=Store::all();

        //充值记录关联会员，公司，门店
        $deposits=Deposit::where($where)->with('oncustomer')->with('company')->with('store')->where($where)->where('is_pay',1)->orderBy('created_at','desc')->paginate(10);

        return view('admin.order.redeposit',compact('deposits','cates'));
    }



}
